var express = require('express');
var getRouter = express.Router();
var postRouter = express.Router();
var axios = require('axios')
var rootApi = "http://112.74.105.17:20003/question-bank"
/* GET users listing. */
getRouter.get('/findQuestion', function (req, res, next) {
    console.log(req.query.data)
    var thisApi = '/wx/stem/'
    var questionId = req.query.data
    axios.get(rootApi + thisApi + questionId)
        .then(function (response) {
            res.send(response.data);
        })
        .catch(function (error) {
            console.log(error);
        });

});

postRouter.post('/findQuestion', function (req, res, next) {
    var thisApi = '/wx/stem/search'
    var findKeyWord=JSON.stringify(req.body.name)
    findKeyWord=findKeyWord.substring(1,(findKeyWord.length-1))
    console.log(findKeyWord)
    axios.post(rootApi + thisApi, {
        // firstName: 'Fred',
        // lastName: 'Flintstone'
        name:findKeyWord
    })
        .then(function (response) {
            res.send(response.data.data)
        })
        .catch(function (error) {
            console.log(error);
        });
});

exports.get = getRouter;
exports.post = postRouter;
// module.exports = router;
